# vim: ts=4:sw=4:syntax=perl
use gri_secmgr qw(get_user_name);

sub mm_send_email3 {
my ($role,$user)=@_;

	my $r2=hex_to_string($role);
	my $u2=hex_to_string($user);
	my $v=get_user_name();
	if($v eq "public") {
		return "Unable to send mail - user logged in as 'public'";
	}
	my $email=$::GRI_FRONTEND->get_user_email_address($v);
	my $mail_to=$::GRI_FRONTEND->get_email_address("access_requests");
	if(!defined($email) || !length($email)) {
		return html_error("Failed to send message - unable to resolve name '$v' to email address.",0);
	}
	if(!defined($email_to) || !length($email_to)) {
		return html_error("Failed to send message - unable to address for access requests.",0);
	}
	my $from=$::GRI_FRONTEND->get_email_sent_from_address();

	my $subject="Request ROLE access: $v // $r2";
	my $cc="User '$email' has requested access to role '$r2'.\n";
	my ($rc,$err)=$::GRI_FRONTEND->send_email({html=>1,subject=>$subject,to=>$mail_to,from=>$from,content=>$cc});
	if($rc) {
		return "A request for access to role '$r2' for user ID '$v' [$email] been successfully send to '$mail_to'.";

	} else {
		return html_error($err,0);
	}
}

1;
